using System;
using UnityEditor;
using UnityEngine;

namespace Gameplay.PVE.Editor
{
    
    public class RpgShootEditorWindow : EditorWindow
    {
        [MenuItem("GTATools/GamePlay/PVE/RpgShootEditor")]
        public static void Init()
        {
            var window = EditorWindow.GetWindow<RpgShootEditorWindow>("rpg射击编辑器", true);
            Instance.Initialize();
        }
     
        public static RpgShootEditorWindow Instance;
        
        public RpgShootEditorWindow()
        {
            Instance = this;
        }
        
        private void Initialize()
        {
            RpgShootEditorManager.Instance.Init();
        }

        private void OnInspectorUpdate()
        {
            //RpgShootEditorManager.Instance.Update();
        }

        private string speedString = "30";
        private string durationString = "1";
        private string countString = "10";
        
        private void OnGUI()
        {
            if (GUILayout.Button("刷新"))
            {
                RpgShootEditorManager.Instance.Refresh();
            }
            GUILayout.Space(20);
            
            if (GUILayout.Button("创建我方"))
            {
                RpgShootEditorManager.Instance.CreateMy();
            }
            if (GUILayout.Button("创建敌方"))
            {
                RpgShootEditorManager.Instance.CreateEnemy();
            }
            if (GUILayout.Button("创建障碍物"))
            {
                RpgShootEditorManager.Instance.CreateWall();
            }
            if (GUILayout.Button("创建车子"))
            {
                RpgShootEditorManager.Instance.CreateCar();
            }

            GUILayout.Space(20);
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("飞行速度");
            speedString = EditorGUILayout.TextField(speedString);
            EditorGUILayout.EndHorizontal();
            
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("持续时间");
            durationString = EditorGUILayout.TextField(durationString);
            EditorGUILayout.EndHorizontal();
            
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("子弹数量");
            countString = EditorGUILayout.TextField(countString);
            EditorGUILayout.EndHorizontal();
            
            if (GUILayout.Button("手枪射击"))
            {
                PrepareData();
                RpgShootEditorManager.Instance.ShootHG();
            }
            if (GUILayout.Button("冲锋枪射击"))
            {
                PrepareData();
                RpgShootEditorManager.Instance.ShootSMG();
            }
            if (GUILayout.Button("机枪射击"))
            {
                PrepareData();
                RpgShootEditorManager.Instance.ShootMG();
            }
            if (GUILayout.Button("自动步枪射击"))
            {
                PrepareData();
                RpgShootEditorManager.Instance.ShootAR();
            }
            if (GUILayout.Button("散弹射击"))
            {
                PrepareData();
                RpgShootEditorManager.Instance.ShootSG();
            }
            if (GUILayout.Button("狙击枪射击"))
            {
                PrepareData();
                RpgShootEditorManager.Instance.ShootSR();
            }

            RpgShootEditorManager.Instance.IsShootGround = GUILayout.Toggle(RpgShootEditorManager.Instance.IsShootGround, "是否射击地板");
        }

        private void PrepareData()
        {
            float speed;
            float.TryParse(speedString, out speed);
            float duration;
            float.TryParse(durationString, out duration);
            int count;
            int.TryParse(countString, out count);
            RpgShootEditorManager.Instance.SetParam(speed,duration,count);
        }
    }
}